package com.jsp.servlet; /**
 * @author wzm
 * @create 2023-03-13 9:25
 */

import com.jsp.entity.Employee;
import com.jsp.service.EmployeeService;
import com.jsp.service.impl.EmployeeServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/deleteById")
public class DeleteServlet extends HttpServlet {
    private EmployeeService employeeService = new EmployeeServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      request.setCharacterEncoding("utf-8");
      response.setContentType("text/html;charset=utf-8");

        String id = request.getParameter("id");

        int i = Integer.parseInt(id);

        boolean b = employeeService.rempveEmp(new Employee(i));
        if(b){
            //删除成功
            response.sendRedirect(request.getContextPath()+"/getAll");
        }else{
            //删除失败
            response.getWriter().write("删除失败~");
        }


    }
}
